package icepuppet.test1;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;

public class HashMapCode {
    public static void main(String[] args) {
        HashMap<Student,String> hashMap = new HashMap();
        Student student1 = new Student("张三",23);
        Student student2 = new Student("李四",24);
        Student student3 = new Student("王五",25);
        hashMap.put(student1,"江西");
        hashMap.put(student2,"四川");
        hashMap.put(student3,"云南");

        //键找值
        Set<Student> keys = hashMap.keySet();
        for (Student key : keys) {
            String value = hashMap.get(key);
            System.out.println(key + "=" + value);
        }

        System.out.println("--------------------------------------");
        //键值对对象
        Set<Map.Entry<Student, String>> entries = hashMap.entrySet();
        for (Map.Entry<Student, String> entry : entries) {
            Student key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key + "=" + value);
        }

        System.out.println("--------------------------------------");
        hashMap.forEach(new BiConsumer<Student, String>() {
            @Override
            public void accept(Student student, String s) {
                System.out.println(student + "=" + s);
            }
        });

        hashMap.forEach((student,s) -> System.out.println(student + "=" + s));
    }
}
